<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">学生姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="stuName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">学生性别</label>
                            <div class="layui-input-inline">
                                <input type="text" name="gender" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">学院</label>
                            <div class="layui-input-inline">
                                <input type="text" name="college" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">学生专业</label>
                            <div class="layui-input-inline">
                                <input type="text" name="major" autocomplete="off" class="layui-input">
                            </div>
                        </div>


                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit  lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>

            </div>

        </fieldset>
        <!--开关-->
        <!--<div class="layui-form-item">-->
        <!--<div class="layui-input-block" >-->
            <!--<input type="checkbox" id="state" name="deleted" lay-skin="switch" lay-text="已参赛完|未参赛完">-->
        <!--</div>-->
        <!--</div>-->
        <script type="text/html" >
            <!-- 这里的 checked 的状态只是演示 -->
            <input type="checkbox" id="state" name="deleted" value="{{d.deleted}}" lay-skin="switch" lay-text="已参赛完|未参赛完" lay-filter="deleted" />
        </script>


        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">

                <button class="layui-btn layui-btn-sm data-add-btn" lay-event="add"> 添加学生</button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除学生 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">成绩录入</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/utils.js"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({

            elem: '#currentTableId',

            id:"tableIns"
            ,done:function(){
            tableData = table.cache.tableIns;
        },
            // url: '../api/table.json',
            url: '/sport/student/lists',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50, fixed: "left"},
                {field: 'id', width: 80, title: '编号', sort: true},
                {field: 'stuNo', width: 80, title: '学号'},
                {field: 'stuName', width: 80, title: '姓名'},
                {field: 'gender', width: 80, title: '性别',minWidth: 150,
                    templet:function (d) {
                        if(d.genderLimit=="1")
                            return '男';
                        else {
                            return '女';
                        }
                    }},
                // {field: 'age', title: '年龄', minWidth: 150},
                {field: 'age', width: 80,title: '年龄'},
                {field: 'college', width: 110, title: '学院'},
                {field: 'major', width: 110, title: '专业'},
                {field: 'className', width: 80, title: '班级'},
                {field: 'email', width: 150, title: '邮箱'},
                {field: 'tel', width: 135, title: '联系方式', sort: true},
                {field: 'deleted', width: 110,templet: '#state', title: '参加状态', sort: true},
                {field: 'time', width: 110, title: '报名时间', sort: true},
                {field: 'achievement', width: 110, title: '成绩', sort: true},
                {title: '操作', minWidth: 50, templet: '#currentTableBar', fixed: "right", align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });
        //监听性别操作
        // form.on('switch(deleted)', function(obj){
        //     layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
        //
        // });
        var static1;
        // 开关 没用到
        form.on('switch(deleted)',function (data) {
            //开关是否开启，true或者false
            static1 = data.elem.checked?0:1;

            //获取所需属性值
            // var static1 = data.elem.attributes['deleted'].nodeValue;
            $.get("/sport/student/list",{"id":id,"deleted":deleted},function (res) {
                if (res.code ==1){
                    layer.msg(res.msg);
                }

            });
            // console.log(checked);
            // // console.log(switch_goods_id);
            // // 此时进行ajax的服务器访问，如果返回数据正常，则进行后面代码的调用
            // var serverStatus = 1;
            // if(serverStatus){
            //     data.elem.checked = checked;
            // }else {
            //     data.elem.checked = !checked;
            // }
            // form.render();
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加学生',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'project-stuadd.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '成绩录入',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['50%', '50%'],
                    content: 'achievement.html?stuid='+data.id+"&pid="+GetQueryString_new("pid"),
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    $.getJSON("/sport/student/del", {id: obj.data.id}, function (res) {

                        if (res.code == 0) {
                            layer.alert(res.msg)
                        } else {
                            layer.alert(res.msg)
                        }

                    })
                    layer.close(index);
                });
            }
        });

    });
</script>
<script>

</script>

</body>
</html>